﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>arrays</title>
</head>
    <body>
        <ul>
            <li>In most languages, the elements of an array are all required to be of the same type. JavaScript allows an array to contain any mixture of values:</li>
            <li>The length property is the largest integer property name in the array plus one. This is not necessarily the number of properties in the array</li>
            <li>The length can be set explicitly. Making the length smaller will cause all properties with a subscript that is greater than or equal to the new length to be deleted:</li>
            <li>A new element can be appended to the end of an array by assigning to the array's current length</li>
            <li>It is sometimes more convenient to use the push method to accomplish the same thing</li>
        </ul>
        <script type="text/javascript">
            var arrays = {
                arrayLiteral: function() {
                    var empty = [];
                    var numbers = [
                        'zero', 'one', 'two', 'three', 'four',
                        'five', 'six', 'seven', 'eight', 'nine'
                    ];

                    return empty[1] == undefined &&
                        numbers[1] == 'one' &&
                        empty.length == 0 &&
                        numbers.length == 10;
                }(),
                objectLiteral: function() {
                    var numbers_object = {
                        '0': 'zero', '1': 'one', '2': 'two',
                        '3': 'three', '4': 'four', '5': 'five',
                        '6': 'six', '7': 'seven', '8': 'eight',
                        '9': 'nine'
                    };
                    return "doesn't inherit from Array so less properties and methods";
                }(),
                deleting: function () {
                    var numbers = [
                        'zero', 'one', 'two', 'three', 'four',
                        'five', 'six', 'seven', 'eight', 'nine'
                    ];
                    delete numbers[2];
                    var ok = numbers[2] == undefined;

                    numbers.splice(2, 1);
                    return ok && numbers[2] == 'three';
                    return ok && numbers[2] == 'three';
                }(),
            };
        </script>
    </body>
</html>
